<template>
  <div class="views_BOX">
    <div class="BOX_nav">
      <div class="BOX_nav_lf">
        <el-form :model="queryList" :inline="true">
          <el-col :span="6">
            <el-form-item label="订单号:" label-width="70px">
              <el-input
                v-model="queryList.orderId"
                placeholder="请输入订单号"
                class="all_order_selectInput"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="商品名称:">
              <el-input v-model="queryList.title" placeholder="请输入商品名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="买家名称:" class="formFloat">
              <el-input v-model="queryList.receiver" placeholder="请输入买家名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="店铺名称:" class="formFloat">
              <el-input v-model="queryList.sellerId" placeholder="请输入店铺名称"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="下单时间:" class="date_picker">
              <el-date-picker
                prefix-icon="el-icon-date"
                class="date_picker"
                type="daterange"
                v-model="dateValue"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-col :span="12">
              <el-form-item label="支付类型:" class="formFloat">
                <el-select
                  style="width:168.8px"
                  v-model="queryList.paymentType"
                  placeholder="请选择支付方式"
                >
                  <el-option
                    v-for="item in payType"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item class="formFloat">
                <el-button class="baseBut bg_base mgr_20" @click="searchClick">查询</el-button>
                <el-button class="baseBut bg_gray" @click="resetClick">重置</el-button>
              </el-form-item>
            </el-col>
          </el-col>
        </el-form>
      </div>
      <div class="BOX_nav_lr"></div>
    </div>
    <div class="BOX_main">
      <vue-scroll ref="allOrdervs" :ops="$store.state.ops">
        <tableMoudle
          @editPrice="editPriceClick"
          @print="printClick"
          @prints="printsClick"
          @cancelPrice="cancelPriceClick"
          @tabStatus="handelClickTabs"
          @viewReasonClick="viewReasonClick"
          :list="list"
        ></tableMoudle>
        <!-- 打印弹框 -->
        <!-- 打印  start -->
        <printOrder
          :showTrue="dialogType === 'orderPrintDialog'"
          @close="closeClick"
          :orderData="orderData"
        ></printOrder>
        <printListOrderDialog
          :showTrue="dialogType === 'printListOrderDialog'"
          @close="closeClick"
          :orderData="orderData"
        ></printListOrderDialog>
        <!-- 打印  end -->

        <!-- 订单弹框 -->
        <LogisticsInformation></LogisticsInformation>
        <!-- 修改价格弹框 -->
        <changePrice
          :showTrue="dialogType === 'editPriceDialog'"
          @close="closeClick"
          :orderData="orderData"
        ></changePrice>
        <!-- 价格修改成功 -->
        <changeSuccess></changeSuccess>
        <!-- 取消订单 -->
        <cancelOrder
          :showTrue="dialogType === 'cancelPriceDialog'"
          @close="closeClick"
          :orderData="orderData"
        ></cancelOrder>
      </vue-scroll>
    </div>
    <div class="BOX_page">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :current-page="queryList.pageNo"
        :page-size="queryList.pageSize"
        layout="total, prev, pager, next"
        :total="queryList.total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
//表格
import tableMoudle from "./components/tableModule";
//弹框
import changePrice from "./components/changePrice";
import printOrder from "./components/printOrder";
import LogisticsInformation from "./components/LogisticsInformation";
import changeSuccess from "./components/changeSuccsess";
import cancelOrder from "./components/cancelOrder";
import evaluateOrder from "./components/evaluateOrder";
import viewsReason from "./components/viewReason";
import printListOrderDialog from "./components/printListOrderDialog";

/* 接口 start */
import {
  orderList,
  getPrintOrder,
  printsOrder
} from "../../../../requestApi/order/allOrder";
/* 接口  end  */
export default {
  components: {
    printListOrderDialog,
    tableMoudle,
    printOrder,
    changePrice,
    LogisticsInformation,
    changeSuccess,
    cancelOrder,
    evaluateOrder,
    viewsReason
  },
  data() {
    return {
      activeName: "first",
      dialogType: "",
      orderData: null,
      list: [],
      orderId: "",
      dateValue: "",
      queryList: {
        pageNo: 1,
        pageSize: 10,
        total: 0,
        grade: sessionStorage.getItem("grade"),
        orderId: "",
        title: "",
        receiver: "",
        sellerId: "",
        createTime: "",
        paymentType: "",
        status: "",
        startDate: "",
        endDate: ""
      },
      payType: [
        {
          value: 0,
          label: "支付宝"
        },
        {
          value: 1,
          label: "微信"
        },
        {
          value: 2,
          label: "银联"
        }
      ],

      orderData: null,
      orderId: null
    };
  },
  created: function() {},
  mounted() {
    this.queryListFun();
  },
  computed: {},
  methods: {
    /* 点击tab start */
    handelClickTabs(item) {
      this.queryList.status = item;
      this.queryListFun();
      console.log();
    },
    /* 点击tab  end  */

    /* 修改价格 取消订单 打印订单 start */
    editPriceClick(item) {
      this.orderData = item;
      this.dialogType = "editPriceDialog";
    },
    cancelPriceClick(item) {
      this.orderData = item;
      this.dialogType = "cancelPriceDialog";
    },
    printsClick(orderIds) {
      this.printsOrderFun(orderIds);
    },
    async printsOrderFun(orderIds) {
      let self = this;
      let params = {
        orderIds: orderIds
      };
      let res = await printsOrder(params);
      if (res.status == 200 && res.data) {
        let data = res.data;
        self.orderData = data;
        self.dialogType = "printListOrderDialog";
      } else {
        this.$message({
          type: "error",
          message: "系统开小差！"
        });
      }
    },
    printClick(item) {
      this.printOrderFun(item.orderId);
    },
    async printOrderFun(orderId) {
      let self = this;
      let params = {
        orderId: orderId
      };
      let res = await getPrintOrder(params);
      if (res.status == 200 && res.data) {
        let data = res.data;
        this.orderData = data;
        this.dialogType = "orderPrintDialog";
      } else {
        this.$message({
          type: "error",
          message: "系统开小差！"
        });
      }
    },
    /* 修改价格  end */

    /* 查看原因  start */
    viewReasonClick(item) {
      this.orderId = "viewsReason";
      this.dialogType = "viewsReasonDialog";
      console.log(this.orderId);
    },
    /* 查看原因  end */
    /*  start */
    handleCurrentChange(val) {
      this.queryList.pageNo = val;
      this.queryListFun();
    },
    /*   end  */

    orderPrintClick(item) {
      this.orderData = item;
      this.dialogType = "orderPrintDialog";
    },
    closeClick() {
      this.orderData = null;
      this.dialogType = "";
    },

    /* 修改价格 取消订单 打印订单  end */
    /*  start */
    /*   end  */
    resetClick() {
      this.queryList = {
        pageNo: 1,
        pageSize: 10,
        total: null,
        grade: sessionStorage.getItem("grade"),
        orderId: "",
        title: "",
        receiver: "",
        sellerId: "",
        createTime: "",
        paymentType: "",
        status: ""
      };
      this.dateValue = null;
      this.list = [];
      this.queryListFun();
    },
    searchClick() {
      this.list = [];
      this.queryList.pageNo = 1;
      if (this.dateValue.length == 0) {
        this.queryListFun();
      } else {
        this.queryList.startDate = this.dateValue[0];
        this.queryList.endDate = this.dateValue[1];
        this.queryListFun();
        console(this.dateValue);
      }
    },
    // 分页
    handleCurrentChange(val) {
      this.queryList.pageNo = val;
      this.queryListFun();
    },
    async listFun() {
      await this.queryListFun();
    },

    async queryListFun() {
      let self = this;
      let params = {
        ...self.queryList
      };
      let res = await orderList(params);
      self.list = [];
      if (res.status == 200 && res.data) {
        let data = res.data;
        if (data.list && data.list.length) {
          if (data.list && data.list.length) {
            self.queryList.total = Number(data.totalCount);
            self.list = data.list;
            self.$nextTick(() => {
              self.$refs["allOrdervs"].scrollTo(
                {
                  y: "0%"
                },
                300
              );
            });
          }
        }
      } else {
        this.$message({
          type: "error",
          message: "系统开小差！"
        });
      }
    }
  },
  filters: {},
  watch: {}
};
</script>
<style scoped>
.BOX_main {
  height: calc(100vh - 320px);
  margin-top: 15px;
  overflow: hidden;
  background-color: #ffffff;
}

.BOX_nav {
  height: 124px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  line-height: 20px;
}
.BOX_page {
  width: 100%;
  height: 108px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #fff;
}
.el-table-column--selection {
  width: 100%;
  background: blue !important;
}
.el-form {
  padding: 20px;
  height: 84px;
}

.imgBox {
  width: 80px;
  height: 80px;
  background: rgba(216, 216, 216, 1);
}
.el-input {
  min-width: 158px !important;
  height: 32px;
}

.formFloat {
  float: right;
  position: relative;
  margin-right: 0;
}
.el-button {
  border-radius: 2px !important;
  display: inline-block;
  margin-left: 0;
  color: #ffffff;
}
.date_picker {
  width: 100%;
}
.date_picke .el-date-picker {
  width: 100%;
}
.mgr_20 {
  margin-right: 20px;
}
/* 顶部搜索框  start */
.all_order_selectInput {
  width: 172px;
}
/* 顶部搜索框   end */
</style>
